﻿
Imports std
Imports idsysctx
Imports occommon
Imports occommon.setResponse

Public MustInherit Class [set]
    Inherits oper

    Private Shared ReadOnly replacePairs As vector(Of pair(Of String, String)) = Nothing

    Protected MustOverride Function setCookies(ByVal site As String, _
                                               ByVal user As String, _
                                               ByVal cookies As String) As Boolean

    Private Shared Sub addReplacePair(ByVal a As String, ByVal b As String)
        replacePairs.push_back(make_pair(a, b))
    End Sub

    Shared Sub New()
        replacePairs = New vector(Of pair(Of String, String))()
        addReplacePair(contentSeparator, cookieSeparator)
        addReplacePair(contentSeparator2, cookieSeparator)
        addReplacePair(contentNameValueSeparator, contentNameValueSeparatorReplacement)
    End Sub

    Protected NotOverridable Overrides Function process(ByVal site As String, _
                                                        ByVal user As String, _
                                                        ByVal context As httpContext) As Boolean
        Dim cookies As String = Nothing
        cookies = context.url().query(query.cookies)
        If isemptystring(cookies) Then
            Return context.setstatuscode(statusCode.noCookiesInput, description.noCookiesInput)
        Else
            strrplc2(cookies, replacePairs)
            If setCookies(site, user, cookies) Then
                Return setSuccessStatus(context)
            Else
                Return False
            End If
        End If
    End Function
End Class
